export function getBaseUrl (isServer, req) {
    let basePath = 'http://192.168.1.230:8280/api'
    if (isServer) {
        if (req.headers.host.toLowerCase().indexOf('uat.haogys') >= 0) {
            basePath = 'http://uat.haogys.com/api'
        } else if (req.headers.host.toLowerCase().indexOf('m.haogys') >= 0) {
            basePath = 'http://www.haogys.com/api'
        }
    } else {
        if (window.location.host.toLowerCase().indexOf('uat.haogys') >= 0) {
            basePath = 'http://uat.haogys.com/api'
        } else if (window.location.host.toLowerCase().indexOf('m.haogys') >= 0) {
            basePath = 'http://www.haogys.com/api'
        }
    }
    return basePath
}

export function getQueryString (params) {
    var query = []
    for (let item in params) {
        if (params[item]) {
            query.push(item + '=' + params[item])
        }
    }
    if (query.length === 0) {
        return ''
    }
    return query.join('&')
}

export function getQueryByName (name) {
    var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i')
    var query = window.location.search.split('?')[1]
    if (query) {
        var r = query.match(reg)
        if (r != null) {
            return unescape(r[2])
        }
    }
    return null
}

export function getPropertyCount (o) {
    let n
    let count = 0
    for (n in o) {
        if (o.hasOwnProperty(n)) {
            count++
        }
    }
    return count
}
export function isWeiXin () {
    var ua = window.navigator.userAgent.toLowerCase()
    if (ua.match(/MicroMessenger/i) == 'micromessenger') { // eslint-disable-line
        return true
    } else {
        return false
    }
}

export function getSideBarIconIndexByName (name) {
    switch (name) {
    case '全部分类':
        return 0
    case '刀具量具':
        return 1
    case '工具':
        return 2
    case '加工作业':
        return 3
    case '气动及液压':
        return 4
    case '流体设备及管件':
        return 5
    case '焊割设备':
        return 6
    case '紧固件':
        return 7
    case '密封件':
        return 8
    case '物流及包装':
        return 9
    case '动力传动':
        return 10
    case '电气控制':
        return 11
    case '检测仪器仪表':
        return 12
    case '照明器材':
        return 13
    case '暖通空调':
        return 14
    case '安全防护':
        return 15
    case '清洁用品':
        return 16
    case '专用件':
        return 17
    case '办公用品':
        return 18
    default:
        return 0
    }
}
